//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package xyz.yuzegod.megawalls.classes.novice.him;

import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ParticleEffect;
import xyz.yuzegod.megawalls.util.PlayerUtils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MainSkill extends Skill {
    public MainSkill(Classes classes) {
        super("雷神之怒", classes);
    }

    public int maxedLevel() {
        return 5;
    }

    public double getAttribute(int level) {
        switch (level) {
            case 1:
                return 3.2;
            case 2:
                return 3.7;
            case 3:
                return 4.1;
            case 4:
                return 4.5;
            case 5:
                return 5.0;
            default:
                return 3.2;
        }
    }

    public List<String> getInfo(int level) {
        List<String> lore = new ArrayList();
        lore.add(" §8▪ §7释放雷神之怒,");
        if (level == 1) {
            lore.add("   §7对附近的敌人造成§a" + this.getAttribute(level) + "§7点伤害。");
            lore.add(" ");
            lore.add("§7冷却时间:§a1秒");
            return lore;
        } else {
            lore.add("   §7对附近的敌人造成§8" + this.getAttribute(level - 1) + " ➜ §a" + this.getAttribute(level) + "§7点伤害。");
            return lore;
        }
    }

    public void upgrade(GamePlayer gamePlayer) {
        KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkillLevel();
    }

    public int getPlayerLevel(GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkillLevel();
    }

    public boolean use(GamePlayer gamePlayer, KitStatsContainer kitStats) {
        Player player = gamePlayer.getPlayer();
        if ((Integer)HIM.skillCooldown.getOrDefault(gamePlayer, 0) > 0) {
            player.sendMessage("§c技能正在冷却中！");
            return false;
        } else {
            List<Player> players = this.getNearbyPlayers(player, 5);
            if (players.isEmpty()) {
                player.sendMessage("§c没有玩家在目标范围内！");
                return false;
            } else {
                List<GamePlayer> gamePlayers = GamePlayer.getGamePlayers();
                gamePlayers.remove(gamePlayer);
                gamePlayers.forEach((otherx) -> {
                    StringBuffer sb = new StringBuffer();
                    Iterator var4 = players.iterator();

                    while(var4.hasNext()) {
                        Player otherPlayer = (Player)var4.next();
                        GamePlayer gameOther = GamePlayer.get(otherPlayer.getUniqueId());
                        if (!gamePlayer.getGameTeam().isInTeam(gameOther)) {
                            sb.append(gamePlayer.getDisplayName(otherx) + "§e, ");
                        }
                    }

                    String text = sb.toString().substring(0, sb.toString().length() - 4);
                });
                StringBuffer sb = new StringBuffer();

                for (Player other : players) {
                    GamePlayer gameOther = GamePlayer.get(other.getUniqueId());
                    if (!gamePlayer.getGameTeam().isInTeam(gameOther)) {
                        LightningStrike lightningStrike = other.getWorld().strikeLightning(other.getLocation());
                        lightningStrike.setMetadata(MegaWalls.getMetadataValue(), new FixedMetadataValue(MegaWalls.getInstance(), gamePlayer.getGameTeam()));
                        ParticleEffect.LAVA.display(0.0F, 0.0F, 0.0F, 1.0F, 5, other.getLocation(), 10.0);
                        other.damage(this.getAttribute(kitStats.getSkillLevel()));
                        gameOther.setLastDamage(gamePlayer, System.currentTimeMillis());
                        sb.append(other.getDisplayName() + "§e, ");
                    }
                }

                String text = sb.toString();
                gamePlayer.sendMessage("§e你的的雷神之怒击中了" + text + "§e！");
                HIM.skillCooldown.put(gamePlayer, 1);
                return true;
            }
        }
    }

    public String getSkillTip(GamePlayer gamePlayer) {
        return this.getClasses().getNameColor() + "§l" + this.getName() + " " + ((Integer)HIM.skillCooldown.getOrDefault(gamePlayer, 0) == 0 ? (gamePlayer.getEnergy() == 100 ? "§a§l✓" : "§c§l✕") : "§c§l" + HIM.skillCooldown.get(gamePlayer) + "秒");
    }

    private List<Player> getNearbyPlayers(Player player, int radius) {
        List<Player> players = new ArrayList();
        Iterator var4 = PlayerUtils.getNearbyPlayers(player, (double)radius).iterator();

        while(var4.hasNext()) {
            Player other = (Player)var4.next();
            GamePlayer gameOther = GamePlayer.get(other.getUniqueId());
            if (!gameOther.isSpectator() && !GamePlayer.get(player.getUniqueId()).getGameTeam().isInTeam(gameOther)) {
                players.add(other);
            }
        }

        return players;
    }
}
